package personal.xjl._23java1studentdemo.controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import personal.xjl._23java1studentdemo.service.StudentService;
@Controller
public class LoginController {
    @Autowired
    StudentService studentService;

    //登录
    @RequestMapping("login")
    public String login() {
        return "login";
    }
    //登出
    @RequestMapping("logout")
    public String logout(HttpSession session) {
        session.invalidate();
        return "login";
    }

    @RequestMapping(loginValidata)
    public String loginValidata(int role,String username,String password,Model model,HttpSession session){
        switch(role){
            case 1:
            {

            }
        }

    }
    @RequestMapping("toPage")
    public String toPage(String page){
        return page;
    }
    //登录验证
    @RequestMapping("loginValidate")
    public String loginValidate(String username, String password, Model model, HttpSession session) {
        //如果登入成功，
        if (studentService.login(username, password)) {
            //给登入成功的用户发放令牌，名称是username
            session.setAttribute("username", username);
            return "redirect:/Student/list/1/3";
        } else
            return "redirect:/login";
    }
}
